﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OgilvyOne.BLL;
using System.Data;


public partial class allergy_lore_article_list : System.Web.UI.Page
{
    protected int pageNum = 1;
    protected int pageCount = 0;
    protected int total;
    protected string columnId;
    protected string classId;
    protected string ename;
    protected string know_ename;
    protected string cid;
    protected string pename;

    protected string titles;
    protected string meta_kwords;
    protected string meta_desc;

    protected string columnpic;
    protected string h1name;


    protected void Page_Load(object sender, EventArgs e)
    {


        columnId = Request["columnId"];
        classId = Request["classId"];
        if (columnId == "197")
        {
            columnpic = "4_1.png";
        }
        else if (columnId == "199")
        {
            columnpic = "4_2.png";
            h1name = "宝宝过敏";
        }
        else if (columnId == "198")
        {
            columnpic = "4_3.png";
            h1name = "宝宝过敏症状";
        }
        else if (columnId == "200")
        {
            columnpic = "4_4.png";
        }

        DataTable dtable = BLLArticleInfo.getEname(columnId);
        foreach (DataRow row in dtable.Rows)
        {
            ename = row["ECLASSNAME"].ToString();
        }

        DataTable seodt = BLLArticleInfo.getSeoInfo(columnId);
        foreach (DataRow seorows in seodt.Rows)
        {
            titles = seorows["Columntitle"].ToString();
            meta_kwords = seorows["ColumnKeyword"].ToString();
            meta_desc = seorows["ColumnDesc"].ToString();
            h1name = titles;
        }

        string pid;
        DataTable piddt = BLLArticleInfo.getpid(columnId);
        foreach (DataRow row1 in piddt.Rows)
        {
            pid = row1["PARENTID"].ToString();
            if (pid == "196")
            {
                pename = "lore";
            }
            else if (pid == "204")
            {
                pename = "plan";
            }
            else if (pid == "205")
            {
                pename = "doctor";
            }
            else if (pid == "179" && cid == "204")
            {
                pename = "plan";
            }

            else if (pid == "179" && cid == "196")
            {
                pename = "lore";
            }
            else if (pid == "179" && cid == "180")
            {
                pename = "index";
            }
        }
        total = BLLArticleInfo.count(columnId);
        if ((total % 4) == 0)
        {
            pageCount = total / 4;
        }
        else
        {
            pageCount = (total / 4) + 1;
        }

        PagerControl1.LoadData = new LoadDataHandler(this.LoadPagingArticle);
        PagerControl1.GetPagerUrl = new GetPagerUrlHandler(this.GetPagerUrl);

        int pnum = 0;
        if (Request.Params["pnum"] != null || Request.Params["pnum"] != "")
            pnum = Convert.ToInt32(Request.Params["pnum"]);

        if (!IsPostBack)
        {
            //loadArticle();
            PagerControl1.PagingParams.TotalCount = total;
            PagerControl1.PagingParams.PageSize = 4;
            PagerControl1.PagingParams.CurrentPageIndex = pnum;
            LoadPagingArticle(PagerControl1.PagingParams);
        }
        

        //banner 你知道吗
        DataTable knowdt = BLLArticleInfo.selectc("isbanner", "1");
        foreach (DataRow row1 in knowdt.Rows)
        {
            cid = row1["COLUMNID"].ToString();
        }
        DataTable dtable_know = BLLArticleInfo.getEname(cid);
        foreach (DataRow row in dtable_know.Rows)
        {
            know_ename = row["ECLASSNAME"].ToString();
        }

        this.banner_rpt.DataSource = knowdt;
        this.banner_rpt.DataBind();
    }

    //protected void page_Command(object sender, CommandEventArgs e)
    //{
    //    if (ViewState["pageNum"] != null)
    //    {
    //        pageNum = Convert.ToInt32(ViewState["pageNum"].ToString());
    //    }
    //    if (e.CommandName.Equals("next") || e.CommandName.Equals("nextp"))
    //    {
    //        pageNum++;
    //        if (pageNum > 1 && pageNum <= pageCount)
    //        {
    //            ViewState["pageNum"] = pageNum;
    //            loadArticle();
    //        }
    //    }
    //    else
    //    {
    //        pageNum--;
    //        if (pageNum >= 1 && pageNum <= pageCount)
    //        {
    //            ViewState["pageNum"] = pageNum;
    //            loadArticle();
    //        }
    //    }

    //}
    protected void loadArticle()
    {

        if (ViewState["pageNum"] != null)
        {
            pageNum = Convert.ToInt32(ViewState["pageNum"].ToString());
        }
        DataTable dt = BLLArticleInfo.GetArticle("4", ((pageNum - 1) * 4).ToString(), columnId, columnId);
        this.Art_Dt.DataSource = dt;
        this.Art_Dt.DataBind();

        DataTable dtclass = BLLArticleInfo.getColumnName(classId);
        this.classNm_rpt.DataSource = dtclass;
        this.classNm_rpt.DataBind();
        if (columnId != "196")
        {
            DataTable dtcolumn = BLLArticleInfo.getColumnName(columnId);
            this.columnName_rpt.DataSource = dtcolumn;
            this.columnName_rpt.DataBind();
        }
        //DataTable ttcolumn = BLLArticleInfo.getColumnName(columnId);
        //this.titleName_rpt.DataSource = ttcolumn;
        //this.titleName_rpt.DataBind();

        //妈妈要知道
        this.doKnow_rpt.DataSource = BLLArticleInfo.selectc("5", "doKnow", "1");
        this.doKnow_rpt.DataBind();

        //研究
        this.yanjiu_rpt.DataSource = BLLArticleInfo.selArticle("89");
        this.yanjiu_rpt.DataBind();

    }

    protected void LoadPagingArticle(PagingParameter pagingParams)
    {
        DataTable dt = BLLArticleInfo.GetArticle(pagingParams.PageSize.ToString(), (pagingParams.CurrentPageIndex * 4).ToString(), columnId, columnId);
        this.Art_Dt.DataSource = dt;
        this.Art_Dt.DataBind();

        DataTable dtclass = BLLArticleInfo.getColumnName(classId);
        this.classNm_rpt.DataSource = dtclass;
        this.classNm_rpt.DataBind();
        if (columnId != "196")
        {
            DataTable dtcolumn = BLLArticleInfo.getColumnName(columnId);
            this.columnName_rpt.DataSource = dtcolumn;
            this.columnName_rpt.DataBind();
        }
        //DataTable ttcolumn = BLLArticleInfo.getColumnName(columnId);
        //this.titleName_rpt.DataSource = ttcolumn;
        //this.titleName_rpt.DataBind();

        //妈妈要知道
        this.doKnow_rpt.DataSource = BLLArticleInfo.selectc("5", "doKnow", "1");
        this.doKnow_rpt.DataBind();

        //研究
        this.yanjiu_rpt.DataSource = BLLArticleInfo.selArticle("89");
        this.yanjiu_rpt.DataBind();
    }

    private string GetPagerUrl(int currPageIndex)
    {
        return string.Format("/allergy/lore/{0}_{1}_{2}.html", currPageIndex, classId, columnId);
    }

}
